﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using YAPACS.RisServer.Abstractions;
using YAPACS.RisServer.Services.Dtos;

namespace YAPACS.RisServer.Controllers;
[Authorize]
public class MatchController : AbpControllerBase
{
    private readonly IMatchService _matchService;

    public MatchController(IMatchService matchService)
    {
        _matchService = matchService;
    }

    /// <summary>
    /// 获取未匹配检查高级搜索视图
    /// </summary>
    /// <returns></returns>
    [HttpGet("api/match/get-exam-advanced-search-view")]
    public async Task<IActionResult> GetExamAdvancedSearchView()
    {
        var result = await _matchService.GetExamAdvancedSearchViewAsync();
        return Ok(result);
    }
    /// <summary>
    /// 获取未匹配Study高级搜索视图
    /// </summary>
    /// <returns></returns>
    [HttpGet("api/match/get-study-advanced-search-view")]
    public async Task<IActionResult> GetStudyAdvancedSearchView()
    {
        var result = await _matchService.GetStudyAdvancedSearchViewAsync();
        return Ok(result);
    }
    /// <summary>
    /// 获取未匹配的Study
    /// </summary>
    /// <param name="take"></param>
    /// <param name="skip"></param>
    /// <param name="search"></param>
    /// <returns></returns>
    [HttpPost("api/match/get-studies")]
    public async Task<IActionResult> GetStudies([FromBody] DataGridRequest request)
    {
        var result = await _matchService.GetStudiesAsync(request);
        return Ok(result);
    }
    /// <summary>
    /// 获取未匹配的检查
    /// </summary>
    /// <param name="take"></param>
    /// <param name="skip"></param>
    /// <param name="search"></param>
    /// <returns></returns>
    [HttpPost("api/match/get-exams")]
    public async Task<IActionResult> GetExams([FromBody] DataGridRequest request)
    {
        var result = await _matchService.GetExamsAsync(request);
        return Ok(result);
    }
    [HttpPost("api/match/get-report-exams")]
    public async Task<IActionResult> GetReportExams([FromBody] DataGridRequest request)
    {
        var result = await _matchService.GetReportExamsAsync(request);
        return Ok(result);
    }
    /// <summary>
    /// 匹配
    /// </summary>
    /// <param name="studyIds"></param>
    /// <param name="examId"></param>
    /// <returns></returns>
    [HttpPost("api/match/{examId}")]
    public async Task<IActionResult> Match([FromForm]IList<Guid> studyIds, Guid examId)
    {
        var result = await _matchService.MatchAsync(studyIds, examId);
        return Ok(result);
    }
    /// <summary>
    /// 匹配
    /// </summary>
    /// <param name="studyIds"></param>
    /// <param name="examId"></param>
    /// <returns></returns>
    [HttpPost("api/match/report/{examId}")]
    public async Task<IActionResult> MatchReport([FromForm] IList<Guid> studyIds, Guid examId)
    {
        var result = await _matchService.MatchReportAsync(studyIds, examId);
        return Ok(result);
    }
}
